﻿@using Backend.JYD.Model;
@using Backend.JYD.Model.Task;
@using Backend.JYD.Business;
@{
    ViewBag.Title = "任务处理";
    Layout = "~/Views/Shared/_LayoutWin.cshtml";

    var nextStatus = ViewBag.NextStatus as TaskManager.TaskStatus?;
    var stepCode = ViewBag.StepCode as TaskManager.StepModelCode?;
}
@using (Ajax.BeginForm("process", new AjaxOptions() { OnSuccess = "afterpost" }))
{
    <div class="ui_pop_body" style="width: 600px; height: 350px;">
        <div>
            <ul class="edit-ul">
            @if (nextStatus.HasValue && nextStatus.Value == TaskManager.TaskStatus.CompleteAndReady)
            {
                var nextModeles = this.ViewBag.NextModeles as List<TaskStepModel>;
                if (nextModeles != null && nextModeles.Count > 0)
                {
                     <li class="li01">
                    <span class="s01"><font color="red">*</font>选择提交步骤：</span>
                    <span class="s02">
                        @foreach (var info in nextModeles)
                        { 
                        <input type="radio" name="rdoStepId" id="@("rdoStepId" + info.StepId)" value="@info.StepId" title="@info.StepName"/>
                        <label for="@("rdoStepId" + info.StepId)">@info.StepName</label><br />
                        }
                    </span>                    
                </li>
                }


                bool useRole = Convert.ToBoolean(ViewBag.UseRole);
                if (useRole)
                {
                    var roleInfos = ViewBag.RoleInfos as List<RoleInfo>;
                <li class="li01">
                    <span class="s01"><font color="red">*</font>选择执行角色：</span>
                    <span class="s02">
                    @if (roleInfos != null && roleInfos.Count > 0)
                    {
                        foreach (var info in roleInfos)
                        { 
                        <input type="checkbox" name="chkId" id="@("chkRole" + info.RoleId)" value="@info.RoleId" title="@info.RoleName"/>
                        <label for="@("chkRole" + info.RoleId)">@info.RoleName</label><br />
                        }
                    }
                    else
                    { 
                        @(new HtmlString("无"))
                    }
                    </span>                    
                </li>
                }
                else
                {
                    var empInfos = ViewBag.EmpInfos as List<EmpInfo>;
                <li class="li01">
                    <span class="s01"><font color="red">*</font>选择执行人：</span>
                    <span class="s02">
                    @if (empInfos != null && empInfos.Count > 0)
                    {
                        foreach (var info in empInfos)
                        { 
                        <input type="checkbox" name="chkId" id="@("chkEmp" + info.EmpId)" value="@info.EmpId" title="@info.EmpName" />
                        <label for="@("chkEmp" + info.EmpId)">@info.EmpName</label><br />
                        }
                    }
                    else
                    { 
                        @(new HtmlString("无"))
                    }
                    </span>
                </li>
                }
            }
                <li class="li01" style="height:90px;">
                    <span class="s01">备注：</span>
                    <span class="s02">
                        <textarea name="remark" id="remark" rows="5" style="width:300px;"></textarea>
                    </span>
                </li>
                <li class="li01">
                    <span class="s01"></span>
                    <span class="s02">
                        <input type="submit" value="提交" onclick="return check()"/>
                        @*@Ajax.ActionLink("提交", "Process", new AjaxOptions { HttpMethod = "POST", OnSuccess = "afterpost" })*@
                        <input type="button" value="取消" onclick="closeWin()"/>
                    </span>
                </li>
            </ul>
        </div>
        <input type="hidden" value="@this.ViewBag.TaskId" name="hidTaskId"/>
        <input type="hidden" value="@this.ViewBag.NextStatus" name="hidNextStatus" />
        <input type="hidden" value="@this.ViewBag.StepCode" name="hidStepCode" />
    </div>
    <script src="@Url.Content("~/skin/js/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script type="text/javascript">
        function afterpost(data) {
            if (data.code) {
                closeWinAndReload();
            }
            else {
                alert(data.msg);

            }
        }

        function check() {
            if ($('input[name="rdoStepId"]').length > 0) {
                if (!$('input[name="rdoStepId"]:checked').val()) {
                    alert("选择执行步骤");
                    return false;
                }
            }
            if($('input[name="chkId"]').length > 0)
            {
                if (!$('input[name="chkId"]:checked').val()) {
                    alert("选择执行人/角色");
                    return false;
                }
            }
            return true;
        }

    </script>
}


